/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.marcelo.agro.core;

import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPopupMenu;
import org.jdesktop.swingx.JXTable;

/**
 *
 * @author marcelo
 */
public class PopupMenuListener extends MouseAdapter {

     JPopupMenu jpopupMenu;
     Point punto;
     JXTable tabla;
        public PopupMenuListener(JPopupMenu jpm, JXTable jXTable) {
            jpopupMenu = jpm;
            tabla =jXTable;
        }
    
        
        
    @Override
    public void mousePressed(MouseEvent e) {
        maybeShowPopUp(e);
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        if (tabla.getSelectedRow()  != -1)
           maybeShowPopUp(e);
    }
    
    private void maybeShowPopUp(MouseEvent evt) {
        
        if (evt.isPopupTrigger()) {
            int row = tabla.rowAtPoint(evt.getPoint());
            if (tabla.isRowSelected(row))
                jpopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
        }
    }
    
    public Point punto(){
       return punto;
    }

}
